﻿using Ay.Framework.WPF.Controls;
using Base.BLL;
using Base.DAL;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Text;

namespace MPSystem.Models
{
    public  class Common
    {
        /// <summary>
        /// 初始化COMBX
        /// </summary>
        /// <param name="_Cobox">ObservableCollection<IAyCheckedItem></param>
        /// <param name="D">Dictionary</param>
        public void LoadCombox(ObservableCollection<IAyCheckedItem> _Cobox, Dictionary<string, string> D)
        {
            _Cobox.Add(new AyCheckBoxItemModel() { ItemText = "请选择", ItemValue = "-1" });
            foreach (KeyValuePair<string, string> p in D)
            {
                _Cobox.Add(new AyCheckBoxItemModel() { ItemText = p.Value, ItemValue = p.Key });
            }
    
        }

        /// <summary>
        /// 初始化COMBX -测区/工作面/巷道/COM口
        /// </summary>
        /// <param name="_Cobox">ObservableCollection<IAyCheckedItem></param>
        /// <param name="D">Dictionary</param>
        public void LoadCombox_IE(ObservableCollection<IAyCheckedItem> _Cobox, IEnumerable I)
        {
            _Cobox.Clear();
            _Cobox.Add(new AyCheckBoxItemModel() { ItemText = "请选择", ItemValue = "-1" });
            foreach (Object obj in I)
            {
                if (obj is Base.DAL.SYSTEMCQB)//这个是类型的判断，这里Student是一个类或结构
                {
                    SYSTEMCQB s = (SYSTEMCQB)obj;//测区
                    {
                        _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.CQMC, ItemValue = s.CQBH.ToString() });
                    }
                }
                if (obj is Base.DAL.SYSTEMGZMB)//工作面
                {
                    SYSTEMGZMB s = (SYSTEMGZMB)obj;
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.GZMMC, ItemValue = s.GZMBH.ToString() });

                }
                if (obj is Base.DAL.SYSTEMXDB)//巷道
                {
                    SYSTEMXDB s = (SYSTEMXDB)obj;
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.XDMC, ItemValue = s.XDBH.ToString() });

                }
                if (obj is Base.DAL.SYSTEMCOMB)//COM口
                {
                    SYSTEMCOMB s = (SYSTEMCOMB)obj;
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.COM, ItemValue = s.COM });

                }
            }

            

        }
        /// <summary>
        /// 返回
        /// </summary>
        /// <param name="I"></param>
        /// <returns></returns>
        public ObservableCollection<IAyCheckedItem> LoadCombox_IECobx( IEnumerable I)
        {
            ObservableCollection<IAyCheckedItem> _Cobox = new ObservableCollection<IAyCheckedItem>();
            _Cobox.Add(new AyCheckBoxItemModel() { ItemText = "请选择", ItemValue = "-1" });
            foreach (Object obj in I)
            {
                if (obj == null) continue;
                if (obj is Base.DAL.SYSTEMCQB)//这个是类型的判断，这里Student是一个类或结构
                {
                    SYSTEMCQB s = (SYSTEMCQB)obj;//测区
                    {
                        _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.CQMC, ItemValue = s.CQBH.ToString() });
                    }
                }
                if (obj is Base.DAL.SYSTEMGZMB)//工作面
                {
                    SYSTEMGZMB s = (SYSTEMGZMB)obj;
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.GZMMC, ItemValue = s.GZMBH.ToString() });

                }
                //巷道
                string[] xdNames = new string[] { "SYSTEMXDB", "View_DBLC_INI_CS", "View_MG_INI_CS", "View_CQYL_INI_CS" };
                Type t = obj.GetType();
                if (obj!=null && xdNames.Contains(t.Name))
                {
                    var xdmc = t.GetProperty("XDMC").GetValue(obj, null);
                    var xdbh = t.GetProperty("XDBH").GetValue(obj, null);
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = xdmc.ToString(), ItemValue = xdbh.ToString() });
                }

                //if (obj is Base.DAL.SYSTEMXDB)//巷道
                //{
                //    SYSTEMXDB s = (SYSTEMXDB)obj;
                //    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.XDMC, ItemValue = s.XDBH.ToString() });

                //}                
                
                if (obj is Base.DAL.SYSTEMCOMB)//COM口
                {
                    SYSTEMCOMB s = (SYSTEMCOMB)obj;
                    _Cobox.Add(new AyCheckBoxItemModel() { ItemText = s.COM, ItemValue = s.COM });

                }
            }

            return _Cobox;

        }


        /// <summary>
        /// 状态COMBX--状态
        /// </summary>
        /// <param name="_Cobox">ObservableCollection<IAyCheckedItem></param>
        /// <param name="D">Dictionary</param>
        public void LoadCombox_Status(ObservableCollection<IAyCheckedItem> _Cobox)
        {
            Dictionary<string, string> D_CQ1 = new Dictionary<string, string>();
            D_CQ1.Add("1", "使用");
            D_CQ1.Add("0", "停用");
            LoadCombox(_Cobox, D_CQ1);
            _Cobox.RemoveAt(0);
        }
        /// <summary>
        /// 状态COMBX--位置
        /// </summary>
        /// <param name="_Cobox">ObservableCollection<IAyCheckedItem></param>
        /// <param name="D">Dictionary</param>
        public void LoadCombox_WZ(ObservableCollection<IAyCheckedItem> _Cobox)
        {
            Dictionary<string, string> D_CQ1 = new Dictionary<string, string>();
            D_CQ1.Add("上部", "上部");
            D_CQ1.Add("中部", "中部");
            D_CQ1.Add("下部", "下部");
            LoadCombox(_Cobox, D_CQ1);
            _Cobox.RemoveAt(0);
        }



        /// <summary>
        /// 获取公司名称
        /// </summary>
        /// <returns></returns>
        public string GetCompanyName()
        {
           var r= ConfigService.GetKM();
            string Name = "abc 矿 业 有 限 公 司 综 采 检 测 报 表";
            try {
                Name= r.KM;
            } catch { }
            return Name;
        }

        /// <summary>
        /// 获取公司名称
        /// </summary>
        /// <returns></returns>
        public string GetSystemName()
        {
            var r = ConfigService.GetKM();
            string Name = "KJ440煤矿顶板压力监测系统—陕西克锐森矿业有限公司";
            try
            {
                Name = ConfigurationManager.AppSettings["SystemName"];
            }
            catch { }
            return Name;
        }


        

        /// <summary>
        /// 上限值
        /// </summary>
        /// <returns></returns>
        public double ZCYL_UpperLimt()
        {
            double Name = 40;
            try
            {
                Name = double.Parse( ConfigurationManager.AppSettings["ZCYL_UpperLimt"]);
            }
            catch { }
            return Name;
        }
        /// <summary>
        /// 上限值
        /// </summary>
        /// <returns></returns>
        public double ZCYL_LowLimt()
        {
            double Name = 40;
            try
            {
                Name = double.Parse(ConfigurationManager.AppSettings["ZCYL_LowLimt"]);
            }
            catch { }
            return Name;
        }
    }
}
